home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_313 / uucp / uucp1.lzh / src / uucico / uucp.c < prev    next >
C/C++ Source or Header  |  1990-01-25  |  4KB  |  234 lines

  1.  
  2. /*
  3.  *   UUCP.c written by William Loftus
  4.  *   Copyright 1988 by William Loftus.    All rights reserved.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include "/version.h"
  9.  
  10. IDENT(".00");
  11.  
  12. char to_buf[128];
  13. char from_buf[128];
  14. char path[128];
  15. char user[8];
  16.  
  17. char command_file[128];
  18. int seq;
  19.  
  20. void BuildReceiveFile();
  21. void BuildSendFile();
  22. void read_ctl();
  23. char *expand_file();
  24. char *strchr();
  25. char *getcwd();
  26.  
  27. #define TRUE 1
  28. #define FALSE 0
  29.  
  30. CXBRK()
  31. {
  32.     return(0);
  33. }
  34.  
  35. void
  36. main(argc,argv)
  37. int argc;
  38. char **argv;
  39. {
  40.     int to_bang, from_bang;
  41.  
  42.     if (argc != 3) {
  43.     printf("Usage: UUCP from_file to_file\n");
  44.     exit(1);
  45.     } else {
  46.     strcat(from_buf, argv[1]);
  47.     strcat(to_buf, argv[2]);
  48.     }
  49.  
  50.     getcwd(path,128);
  51.  
  52.     if (chdir("UUSPOOL:")) {
  53.     printf("Couldn't change current working directory to UUSPOOL:\n");
  54.     exit(1);
  55.     }
  56.  
  57.     read_ctl();
  58.  
  59.     seq = GetSequence(2);
  60.     if (seq < 0) {
  61.     chdir(path);
  62.     exit(1);
  63.     }
  64.  
  65.     from_bang = (int)strchr(from_buf,'!');
  66.     to_bang = (int)strchr(to_buf,'!');
  67.  
  68.     if (from_bang && to_bang) {
  69.     printf("Can not specify a remote system in both arguments.\n");
  70.     chdir(path);
  71.     exit(1);
  72.     }
  73.  
  74.     if (from_bang) {
  75.     BuildReceiveFile();
  76.     }
  77.  
  78.     if (to_bang) {
  79.     BuildSendFile();
  80.     }
  81.  
  82.     chdir(path);
  83.     exit(0);
  84. }
  85.  
  86. void
  87. BuildSendFile()
  88. {
  89.     FILE *fp;
  90.     char system_name[32];
  91.     int bang;
  92.  
  93.     strcpy(from_buf,expand_file(from_buf));
  94.  
  95.     bang = (int)strchr(to_buf,'!');
  96.     bang = bang - (int)to_buf;
  97.  
  98.     strncpy(system_name,to_buf,bang);
  99.  
  100.     system_name[bang] = '\0';
  101.  
  102.     if (!is_in_L_sys_file(system_name)) {
  103.     printf("System \"%s\" not in L.sys file.\n", system_name);
  104.     chdir(path);
  105.     exit(1);
  106.     }
  107.  
  108.     system_name[7] = '\0';
  109.  
  110.     sprintf(command_file,"C.%sA%04d", system_name, seq++);
  111.  
  112.     LockFile(command_file);
  113.  
  114.     fp = fopen(command_file,"w");
  115.  
  116.     if (fp) {
  117.     /* srcnam desnam who flags temp mode who */
  118.     fprintf(fp,"S %s %s %s %s %s %s %s\n",
  119.         from_buf,
  120.         to_buf + bang + 1,
  121.         user,
  122.         "-c",
  123.         from_buf,
  124.         "0666",
  125.         user
  126.     );
  127.     fclose(fp);
  128.     } else {
  129.     UnLockFile(command_file);
  130.     perror(command_file);
  131.     chdir(path);
  132.     exit(1);
  133.     }
  134.     UnLockFile(command_file);
  135.     printf("Command queue for transfer to %s.\n", system_name);
  136. }
  137.  
  138. void
  139. BuildReceiveFile()
  140. {
  141.     FILE *fp;
  142.     char system_name[32];
  143.     int bang;
  144.  
  145.     strcpy(to_buf,expand_file(to_buf));
  146.  
  147.     bang = (int)strchr(from_buf,'!');
  148.     bang = bang - (int)from_buf;
  149.  
  150.     strncpy(system_name,from_buf,bang);
  151.  
  152.     system_name[bang] = '\0';
  153.  
  154.     if (!is_in_L_sys_file(system_name)) {
  155.     printf("System \"%s\" not in L.sys file.\n", system_name);
  156.     chdir(path);
  157.     exit(1);
  158.     }
  159.  
  160.     system_name[7] = '\0';
  161.  
  162.     sprintf(command_file,"C.%sA%04d", system_name, seq++);
  163.  
  164.     LockFile(command_file);
  165.  
  166.     fp = fopen(command_file,"w");
  167.     if (fp) {
  168.     /* srcnam desnam who flags */
  169.     fprintf(fp,"R %s %s %s %s\n",
  170.         from_buf + bang + 1,
  171.         to_buf,
  172.         user,
  173.         "-c"
  174.     );
  175.     fclose(fp);
  176.     } else {
  177.     UnLockFile(command_file);
  178.     perror(command_file);
  179.     chdir(path);
  180.     exit(1);
  181.     }
  182.     UnLockFile(command_file);
  183.     printf("Command queue for transfer from %s.\n", system_name);
  184. }
  185.  
  186. static char name[128];
  187.  
  188. char *
  189. expand_file(file_name)
  190. char *file_name;
  191. {
  192.     char *colon;
  193.  
  194.     colon = strchr(file_name,':');
  195.     if ((colon != (char*)NULL) && (colon != file_name)) {
  196.     return(file_name);
  197.     } else {
  198.     if (path[strlen(path)-1] != ':') {
  199.         sprintf(name,"%s/%s",path,file_name);
  200.         return name;
  201.     } else {
  202.         sprintf(name,"%s%s",path,file_name);
  203.         return name;
  204.     }
  205.     }
  206. }
  207.  
  208. #define CTL_DELIM " \t\r\n"
  209.  
  210. /*
  211.  * Read the control file and grab a few parameters.
  212.  */
  213.  
  214. void
  215. read_ctl()
  216. {
  217.     FILE  *fd;
  218.     static char  buf[128];
  219.  
  220.     if (! (fd = fopen("UULIB:Config", "r"))) {
  221.     printf("Can't Find config file.\n");
  222.     chdir(path);
  223.     exit(3);
  224.     }
  225.  
  226.     while (NULL != fgets(buf, sizeof buf, fd)) {
  227.     if (strncmp(buf, "UserName", 8) == 0)
  228.         strcpy(user, strtok(&buf[9], CTL_DELIM) ) ;
  229.     }
  230.     fclose(fd);
  231. }
  232.  
  233.  
  234.